package com.airport.ticket.service.impl;

import com.airport.ticket.common.PageInfoUtil;
import com.airport.ticket.dao.BoradMapper;
import com.airport.ticket.entity.Borad;
import com.airport.ticket.entity.BoradQuery;
import com.airport.ticket.service.BoradService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class BoradServiceImpl implements BoradService {
    @Autowired
    private BoradMapper baseMapper;

    @Override
    public int save(Borad t) {
        return this.baseMapper.save(t);
    }

    @Override
    public int update(Borad t) {
        return this.baseMapper.update(t);
    }

    @Override
    public int delete(BoradQuery param) {
        return this.baseMapper.deleteBatch(param);
    }

    @Override
    public Borad findOne(BoradQuery param) {
        return this.baseMapper.findOne(param);
    }

    @Override
    public List<Borad> findList(PageInfoUtil pageInfoUtil, BoradQuery param) {
        List<Borad> dataResult = Collections.EMPTY_LIST;
        /* 设置分页相关信息 */
        if(pageInfoUtil != null)
        {
            /* 设置分页信息 */
            Page page = PageHelper.startPage(pageInfoUtil.getCurrentPage(),pageInfoUtil.getPageSize());
            dataResult = this.baseMapper.findList(param) ;
            pageInfoUtil.setTotalRecord(Integer.valueOf(page.getTotal() + ""));
        }else
        {
            dataResult = this.baseMapper.findList(param) ;
        }
        return dataResult;
    }
}
